<template>
<div class="wrapper">
<!-- 页面头部部分 -->
    <div class="header">
        <div class="logo">凯睿</div>
        <div class="logo-icon">
          <img src="@/assets/img/logo.png" alt="">
        </div>
        <!-- 水平一级菜单 -->
        <div style="float:left;">
            <el-menu :default-active="toIndex()" mode="horizontal" @select="handleSelect">
            <template v-for="item in items">
                <el-menu-item :index="item.index" :key="item.index">
                <template slot="title">
                    <span slot="title">{{ item.title }}</span>
                </template>
                </el-menu-item>
            </template>
            </el-menu>
        </div>

        <div class="header-right">
            <div class="header-user-con">
                <!-- 用户头像 -->
<!--                <div class="user-avator"><img src="../../assets/img/img.jpg" /></div>-->
                <!-- 用户名下拉菜单 -->
                <el-dropdown class="user-name" trigger="click">
                    <span class="el-dropdown-link">
                        {{ userName }}
                        <i class="el-icon-caret-bottom"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
<!--                      <el-dropdown-item>帮助</el-dropdown-item>-->
                      <el-dropdown-item @click.stop.native="logout" style="color: red">退出</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </div>
    </div>

    <!-- 页面左侧二级菜单栏，和主体内容区域部分 -->
    <el-main>
        <router-view></router-view>
    </el-main>

</div>
</template>

<script>
import {userInfo, isLogin} from "@/assets/js/api"
export default {
    data() {
        return {
            items: [    // 水平一级菜单栏的菜单
                { index: 'core', title: '核心看板' },
                { index: 'agility', title: '敏捷看板' }
            ],
            userName: '暂未登录',
        }
    },
    computed: {

    },
    created() {
      // this.checkLogin()
    },
  methods:{
        checkLogin(){
          isLogin()
              .then((res) => {
                console.log(res)
                if (res.code === 0) {
                  this.$nextTick(() =>{
                    this.getUserInfo();
                  })
                }else{
                    this.login();
                }
              })
              .catch(() => {
                this.login();
              });
        },
        // 根据路径绑定到对应的一级菜单，防止页面刷新重新跳回第一个
        toIndex() {
            return this.$route.path.split('/')[1];
        },
        // 切换菜单栏
        handleSelect(index) {
            this.$router.push('/' + index);
        },
        // 用户名下拉菜单选择事件
        handleCommand(command) {
            if (command === 'loginout') {
                localStorage.removeItem('ms_username');
                this.$router.push('/login');
            }
        },
        // 退出登录2
        logout() {
          window.location.href = "/ks-data-bussiness-api/logout";
        },
        login() {
          let url =
              "/ks-data-bussiness-api/ks-data-bussiness-api/login?referUrl=" + window.location.href;
          window.location.href = url;
        },
    // 获取用户信息
    getUserInfo(){
      userInfo().then(res=>{
        console.log(res)
        this.userName = res.data.realName
      })
    }
    }
}
</script>

<style scoped>
.logo-icon{
  width: 35px;
  height: 35px;
  position: absolute;
  top: 14px;
  left: 74px;
  background-color: transparent;
}
.logo-icon img{
  width: 100%;
  height: 100%;
}
.wrapper {
    width: 100%;
    height: 100%;
    background: #f5f5f5;
}
.header {
    position: fixed;
    box-sizing: border-box;
    width: 100%;
    height: 70px;
    font-size: 22px;
  z-index: 999;
}
.header .logo {
    float: left;
    height: 100%;
    width: 249px;
    text-align: right;
    padding-right: 87px;
    box-sizing: border-box;
    line-height: 66px;
    background-color: #3C3D4E;
    color: #FFFFFF;
    font-size: 23px;
    font-family: "Myriad Pro","Helvetica Neue",Arial,Helvetica,sans-serif;
    font-weight: 600;
    border-bottom: #8c939d solid 1px;
}
/* --------------- 用户头像区域的样式 ---------------- */
.header-right {
    float: right;
    padding-right: 50px;
}
.header-user-con {
    display: flex;
    height: 70px;
    align-items: center;
}
.user-avator {
    margin-left: 20px;
}
.user-avator img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
}
.user-name {
    margin-left: 10px;
}
.el-dropdown-link {
    cursor: pointer;
}
.el-dropdown-menu__item {
    text-align: center;
}
/* --------------- 水平一级菜单栏的样式--------------------- */
.el-menu.el-menu--horizontal {
    border-bottom: none !important;
    float: left;
    margin-left: 50px;
}
.el-menu--horizontal > .el-menu-item.is-active {
    border-bottom: 2px solid #409eff;
    color: #3989fa;
    font-weight: 700;
}
.el-menu--horizontal > .el-menu-item {
    font-size: 16px;
    margin: 0 15px;
    color: black;
}
</style>
